#include <stdio.h>
#include "crc32.h"

int main() {
    unsigned char data[9] = "123456789";

    CRC32_16 crc32_16;
    crc32_16.crcPoly = 0x04c11db7;
    crc32_16.crcInit = 0xffffffff;
    crc32_16.crcXor = 0xffffffff;
    crc32_16.crcRefIn = 1;
    crc32_16.crcRefOut = 1;

    CRC32_256 crc32_256;
    crc32_256.crcPoly = 0x04c11db7;
    crc32_256.crcInit = 0xffffffff;
    crc32_256.crcXor = 0xffffffff;
    crc32_256.crcRefIn = 1;
    crc32_256.crcRefOut = 1;

    unsigned int crc32;
    unsigned int i;

    create_crc32_table16(&crc32_16);
    crc32 = generate_crc32(&crc32_16, 16, data, 9);
    printf("0x%08x\n", crc32);

    printf("----------\n");

    create_crc32_table256(&crc32_256);
    crc32 = generate_crc32(&crc32_256, 256, data, 9);
    printf("0x%08x\n", crc32);

    printf("----------\n");

    prepare_crc32_with_table16(&crc32_16, &crc32);
    for(i = 0; i < 9; i++) {
        process_crc32_with_table16(&crc32_16, &data[i], &crc32);
    }
    complete_crc32_with_table16(&crc32_16, &crc32);
    printf("0x%08x\n", crc32);

    printf("----------\n");

    prepare_crc32_with_table256(&crc32_256, &crc32);
    for(i = 0; i < 9; i++) {
        process_crc32_with_table256(&crc32_256, &data[i], &crc32);
    }
    complete_crc32_with_table256(&crc32_256, &crc32);
    printf("0x%08x\n", crc32);

    return 0;
}
